import { defineStore } from 'pinia'
import { getToken, setToken } from '@/utils/storage'
import { getUserApi, postUserApi } from '@/api/user'

export const useUserStore = defineStore('user', {
    state: () => {
        return {
            token: getToken(),
            userInfo: {}
        }
    },

    getters: {

    },

    actions: {
        async doLogin(data) { // {loginName,loginKey}
            const res = await postUserApi(data)
            this.token = res?.data?.token
            setToken(res?.data?.token)
            return res
        },
        async getUserInfo(token) {
            const res = await getUserApi({ token })
            this.userInfo = res?.data
        }
    }
})